package com.nuo.test.simplServlet;

import java.io.IOException;
import java.io.InputStream;

public class Request {
	private InputStream input;
	private String uri;
	
	public Request(InputStream input){
		this.input = input;
	}
	
	public void parse(){
		StringBuilder builder = new StringBuilder(2048);
		
		int i;
		byte[] buffer = new byte[2048];
		
		try {
			i = input.read(buffer);
		} catch (IOException e) {
			i = -1;
			e.printStackTrace();
		}
		
		for(int j = 0; j < i; j++){
			builder.append((char)buffer[j]);
		}
		System.out.println(builder.toString());
		
		uri = parseUri(builder.toString());
		
	}
	
	private String parseUri(String requestString){
		int index1 = -1, index2 = -1;
		index1 = requestString.indexOf(' ');
		
		if(index1 != -1){
			index2 = requestString.indexOf(' ', index1 + 1);
			
			if(index2 > index1){
				return requestString.substring(index1 + 1, index2);
			}
		}
		
		return null;
	}
	
	public String getUri(){
		return uri;
	}
	
	
}
